9ec087
@@ -421,7 +421,8 @@
public class FastByteArrayOutputStream extends OutputStream {
 						System.arraycopy(this.currentBuffer, this.nextIndexInCurrentBuffer, b, off, bytesToCopy);
 						this.totalBytesRead += bytesToCopy;
 						this.nextIndexInCurrentBuffer += bytesToCopy;
-						return (bytesToCopy + read(b, off + bytesToCopy, len - bytesToCopy));
+						int remaining = read(b, off + bytesToCopy, len - bytesToCopy);
+						return bytesToCopy + Math.max(remaining, 0);
 					}
 					else {
 						if (this.buffersIterator.hasNext()) {
